﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Home_MyAccount : System.Web.UI.Page
{
    public LanguageManage Language;
    public UserEntity currentUser;
    UserAdapter userAdap;
    protected void Page_Load(object sender, EventArgs e)
    {              
        //Check login
        currentUser = UserManager.Instance.Getuser();
        if (!currentUser.isLogin)
            Response.Redirect("~/Login.aspx");
        Language = new LanguageManage();
        userAdap = new UserAdapter();
        Session["menu_id"] = "myaccount";
        Comp1.Text = Language["Errpassmatch"];
        rvfpasswordnew.Text = Language["ErrNotacceptScharacters"];
        rvfpasswordold.Text = Language["ErrNotacceptScharacters"];
        rvfretype.Text = Language["ErrNotacceptScharacters"];
    }
    public string ConvertActive(bool active)
    {
        if (active == true)
        {
            return "Active";
        }
        else
        {
            return "No active";
        }
    }  
    protected void btn_changePassword_Click(object sender, EventArgs e)
    {
        if (!userAdap.CheckOldPassword(currentUser.Account, txtPasswordOld.Text))
        {
            ErrorOldPass.Text = Language["ErrorPass"];
            return;
        }

        //Update user.
        BookContextDataContext context = new BookContextDataContext();
        AuthenAdapter authen = new AuthenAdapter();
        User user1 = context.Users.SingleOrDefault(t => t.Account == currentUser.Account);
        user1.Password = authen.Encrypt(txtPasswordNew.Text, true);       
        context.SubmitChanges();
        Response.Redirect("~/Login.aspx");
    }
}